package com.catmiao.ai.controller;

import com.catmiao.ai.assistant.ChatAssistant;
import com.catmiao.ai.assistant.ChatMemoryAssistant;
import dev.langchain4j.model.chat.StreamingChatModel;
import dev.langchain4j.model.chat.response.ChatResponse;
import dev.langchain4j.model.chat.response.StreamingChatResponseHandler;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
public class ChatMemoryController {

    @Resource
    private ChatMemoryAssistant chatMemoryWithMaxMessagesAssistant;

    @Resource
    private ChatMemoryAssistant chatMemoryWithMaxTokensAssistant;

    @Resource
    private ChatAssistant chatAssistant;

    @GetMapping("/chat/chat")
    public Flux<String> chat(String prompt){
        return chatAssistant.chatStream(prompt);
    }


    @GetMapping("/chat/chat2")
    public String chat2(String userId,String prompt){

        return chatMemoryWithMaxMessagesAssistant.chatWithChatMemory(userId,prompt);
    }


    @GetMapping("/chat/chat3")
    public String chat3(String userId,String prompt){

        return chatMemoryWithMaxTokensAssistant.chatWithChatMemory(userId,prompt);
    }}
